<template>
  <a-card :bordered="false">

    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="渠道名称">
              <a-input placeholder="请输入渠道名称" v-model="queryParam.name"></a-input>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button v-has="'channel:setProductStatus'" @click="setSyncProcess" type="primary" icon="plus">手动同步金蝶价格</a-button>
      <a-button v-has="'channel:setProductStatus'" @click="getSyncResult" type="primary" icon="plus">查询同步结果</a-button>
    </div>

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a
        style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div>

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        class="j-table-force-nowrap"
        :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange,type:type}"
        @change="handleTableChange">

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
        </span>

      </a-table>
    </div>
    <!-- table区域-end -->

    <a-tabs defaultActiveKey="0">
      <a-tab-pane tab="价格明细" :key="refKeys[2]" :forceRender="true">
        <stmChannelProductList ref="StmChannelProductList"></stmChannelProductList>
      </a-tab-pane>
    </a-tabs>

    <!-- 表单区域 -->
    <stmChannelInfo-modal ref="modalForm" @ok="modalFormOk"></stmChannelInfo-modal>
  </a-card>
</template>

<script>
import '@/assets/less/TableExpand.less'
import StmChannelInfoModal from './modules/StmChannelInfoModal'
import {JeecgListMixin} from '@/mixins/JeecgListMixin'
import {downFile, getAction} from "@api/manage"
import StmChannelProductList from './StmChannelProductList'

export default {
  name: "StmChannelInfoList",
  mixins: [JeecgListMixin],
  components: {
    StmChannelInfoModal,
    StmChannelProductList
  },
  data() {
    return {
      importExcelUrl:`${window._CONFIG['domianURL']}/stm/stmChannelInfo/importChannelProductExcel`,
      description: '渠道表管理页面',
      refKeys: [StmChannelProductList],
      channelId:0,
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1;
          }
        },
        {
          title: '渠道编号',
          align: "center",
          dataIndex: 'channelId'
        },
        {
          title: '渠道名称',
          align: "center",
          dataIndex: 'name'
        },
        {
          title: '是否启用',
          align: "center",
          dataIndex: 'status_dictText'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          scopedSlots: {customRender: 'action'},
        }
      ],
      type: "radio",
      url: {
        list: "/stm/stmChannelInfo/list",
        delete: "/stm/stmChannelInfo/delete",
        deleteBatch: "/stm/stmChannelInfo/deleteBatch",
        exportXlsUrl: "stm/stmChannelInfo/exportXls",
        importExcel: "stm/stmChannelInfo/importExcel",
        setSyncProcess:"sync/sysSyncData/syncData/getPrice",
        getSyncResult:"sync/sysSyncData/syncDataFlush"
      },
    }
  },
  computed: {
  },
  methods: {
    onSelectChange(selectedRowKeys, selectionRows) {
      this.selectedRowKeys = selectedRowKeys;
      this.selectionRows = selectionRows;
      this.channelId = this.selectedRowKeys[0];
      this.$refs.StmChannelProductList.getMain(this.selectedRowKeys[0]);
    },
    setFileClick(info){
      this.channelId =info.id
      this.$refs.import.$el.click();
    },
    setSyncProcess(){
      getAction(this.url.setSyncProcess, {}).then((res) => {
        if (res.success) {
          this.$message.success(res.message);
        } else {
          this.$message.warning(res.message);
        }
      })
    },
    getSyncResult(){
      getAction(this.url.getSyncResult, {}).then((res) => {
        if (res.success) {
          this.$message.success(res.message);
        } else {
          this.$message.warning(res.message);
        }
      })
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>